// 写cookies
export const setCookie = (name, value = '') => {
  if (!name) {
    return
  }
  const Days = 30;
  const exp = new Date();
  exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
  document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + ';path=/'
}

// 取cookies
export const getCookie = name => {
  if (!name) {
    return null
  }

  let arr = [],
      reg = new RegExp("(^| )"+name+"=([^;]*)(;|$)")
  if(arr = document.cookie.match(reg)) {
    return unescape(arr[2])
  }
  return null
}
// 删除token
export const delCookie = name => {
  if (!name) {
    return
  }
  const exp = new Date()
  exp.setTime(exp.getTime() - 1)
  const cval = getCookie(name)
  if(cval != null)
  document.cookie= name + "="+cval+";expires="+exp.toGMTString()
}